from __future__ import print_function
import csv
import sys
import json
import json_formatter_ex

if __name__ == "__main__":
    with open(sys.argv[-1]) as in_file:
        network = json.load(in_file)

    name_group = {}
    for edge in network['edges']:
        if edge['source'] not in name_group.keys():
            name_group[edge['source']] = edge['source_group']
        if edge['target'] not in name_group.keys():
            name_group[edge['target']] = edge['target_group']
    
    for key in network['nodes'].keys():
        if name_group[key] == 1:
            network['nodes'][key]['color'] = 'blue'
        elif name_group[key] == 2:
            network['nodes'][key]['color'] = 'yellow'
        elif name_group[key] == 3:
            network['nodes'][key]['color'] = 'green'
        elif name_group[key] == 4:
            network['nodes'][key]['color'] = 'indigo'
        elif name_group[key] == 5:
            network['nodes'][key]['color'] = 'orange'
        elif name_group[key] == 6:
            network['nodes'][key]['color'] = 'purple'
        elif name_group[key] == 7:
            network['nodes'][key]['color'] = 'gray'

    print(json_formatter_ex.dumps(network))
